<?php

/**
* I18n abstract class
*
* @author b3ha (baloghbh@gmail.com)
*/
abstract class acI18n
{
	/**
	* Language (eg. en) 
	*
	* @var string
	*/	
	protected $language	= NULL;
	/**
	* Dictionary (key, value)
	*
	* @var array
	*/
	protected $dictionary	= array();
	/**
	* Property files
	*
	* @var array
	*/
	protected $properties	= array();

	/**
	* Initialize
	*/
	abstract public function init();
	/**
	* Load a property file from a module
	*
	* @param string $property_path
	* @param string $module
	*/
	abstract public function load($property_name, $module = 'main');
	/**
	* Load a all property files from a module
	*
	* @param string $module
	*/
	abstract public function loadAll($module = 'main');

	/**
	* Get all the loaded property files
	*
	* @return array returns with all the loaded property files.
	*/
	public function getProperties()
	{
		return $this->properties;
	}

	/**
	* Get all elements of the dictionary
	*
	* @return array
	*/
	public function getDictionary()
	{
		return $this->dictionary;
	}

	/**
	* Get the actual language
	*
	* @return string
	*/
	public function getLanguage()
	{
		return $this->language;
	}

	/**
	* Set the actual language
	*
	* @param string $lang
	*/	
	public function setLanguage($lang)
	{
		$this->language	= $lang;
	}

	/**
	* Get a key's value from the dictionary
	*
	* @param string $key
	* @param array $params array('%1' => 'save.txt', '%2' => 'Fulham')
	* @return string
	*/	
	public function get($key, array $params = array())
	{
		if ( ! array_key_exists($key, $this->dictionary)) return $key;

		$result = $this->dictionary[$key];

		if ( ! empty($params))
		{
			foreach ($params as $param_key => $param_val)
			{
				$result = str_replace($param_key, $param_val, $result);
			}
		}

		return $result;
	}
}

# EOF
